import { BasicColumn, FormSchema } from '@/components/Table';
import { getModuleTypeList } from '@/api/module/module';

export const columns: BasicColumn[] = [
  {
    title: '模块名称',
    dataIndex: 'name',
    width: 120,
  },
  {
    title: '模块类型',
    dataIndex: 'type',
    width: 120,
  },
  {
    title: '循环',
    dataIndex: 'is_loop',
    width: 80,
    customRender: ({ record }) => {
      return record.is_loop ? '是' : '否';
    },
  },
  {
    title: '创建时间',
    dataIndex: 'created_at',
    width: 180,
  },
  {
    title: '更新时间',
    dataIndex: 'updated_at',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '模块名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'type',
    label: '模块类型',
    component: 'ApiSelect',
    componentProps: {
      api: getModuleTypeList,
      resultField: 'list',
      labelField: 'name',
      valueField: 'name',
    },
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '模块名称',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'type',
    label: '模块类型',
    component: 'ApiSelect',
    componentProps: {
      api: getModuleTypeList,
      resultField: 'list',
      labelField: 'name',
      valueField: 'name',
    },
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'html',
    label: 'HTML内容',
    component: 'InputTextArea',
    colProps: { span: 24 },
  },
  {
    field: 'is_loop',
    label: '是否循环',
    component: 'Switch',
    defaultValue: false,
    colProps: { span: 24 },
  },
];
